package com.demo.shiro.controlloer;

import com.demo.shiro.model.UserOnline;
import com.demo.shiro.service.SessionService;
import com.demo.shiro.utils.ResponseBo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Jmy
 * @date 2019/8/6 22:33
 * @email jiaomingyu5778@gmail.com
 */
@Api("online 操作在线用户")
@Controller
@RequestMapping("/online")
public class SessionController {

    @Autowired
    SessionService sessionService;

    @ApiOperation(value = "获取所有在线用户信息", notes = "获取系统中所有在线用户信息")
    @GetMapping("list")
    public @ResponseBody List<UserOnline> list() {
        return sessionService.list();
    }

    @ApiOperation(value = "删除用户", notes = "根据用户ID，提出用户信息")
    @ApiImplicitParam(name = "id", value = "用户SessionID", required = true, dataType = "String")
    @RequestMapping("forceLogout")
    public @ResponseBody ResponseBo forceLogout(String id) {
        try {
            sessionService.forceLogout(id);
            return ResponseBo.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseBo.error("踢出用户失败");
        }
    }
}
